package oop.data;

import java.util.Date;
import java.util.List;

import oop.db.dao.MarkDAO;
import oop.db.dao.TestDAO;
import oop.db.dao.UserDAO;

public class Examination {

	private long id;
	private long teacherId;
	private long testId;
	private Date date;
	private String name;
	private String clazz;
	private List<Mark> marks = null;

	public Examination(long id, long teacherId, long testId, Date date,
			String name, String clazz) {
		super();
		this.id = id;
		this.teacherId = teacherId;
		this.testId = testId;
		this.date = date;
		this.name = name;
		this.clazz = clazz;
	}

	public long getId() {
		return id;
	}
	
	public User getTeacher() {
		try {
			return UserDAO.fetchById(teacherId).get(0);
		} catch (Exception e) {
			throw new RuntimeException(e);
		}
	}
	
	public Test getTest() {
		try {
			return TestDAO.fetchById(testId);
		} catch (Exception e) {
			throw new RuntimeException(e);
		}
	}

	public void setTest(Test test) {
		this.testId = test.getId();
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getClazz() {
		return clazz;
	}

	public void setClazz(String clazz) {
		this.clazz = clazz;
	}

	public Date getDate() {
		return date;
	}

	public List<Mark> getMarks() {
		if (marks == null) {
			try {
				marks = MarkDAO.fetchByExamination(id);
			} catch (Exception e) {
				throw new RuntimeException(e);
			}
		}
		return marks;
	}

}
